#include "cardtest3.h"
void testSalvager(struct gameState* state){
    int failed_tests = 0;
    int player = whoseTurn(state);
    int result;
    int preBuys = state->numBuys;
    int preCoins = state->coins;
    int preHandCount = state->handCount[player];
    int bonus = 0;
    int preValue = getCost(handCard(1,state));

    result = cardEffect(salvager,1,0,0,state,0,&bonus);
    if(result !=0 || preCoins+preValue != state->coins){
        printf("Failed on trash and coin gain test on player %i for salvager \n",player);
        failed_tests+=1;
    }
    //two cards must be gone for this particular state to pass, as it shall be done.
    if(preHandCount-2!=state->handCount[player]){
        printf("Failed to discard card as a part of coin gain for player %i for salvager \n",player);
        failed_tests+=1;
    }
    preHandCount = state->handCount[player];
    preBuys= state->numBuys;
    result = cardEffect(salvager,0,0,0,state,0,&bonus);
    if(preBuys+1!=state->numBuys){
        printf("Failed to increment buys on subsequent use of salvager for player %i \n",player);
        failed_tests+=1;
    }
    
    if(state->handCount[player]>=preHandCount){
        printf("Failed to discard card for use of salvager for player %i \n",player);
        failed_tests+=1;
    }
    if(failed_tests==0){
        printf("All tests passed for salvager card \n");
    }
    else{
        printf("Number of tests that failed for salvager card: %i\n",failed_tests);
    }
}
int main(int argc, char** argv){
    int cards[10] = {adventurer, council_room, feast, gardens, mine,
        remodel, smithy, village, baron, salvager};
    
    struct gameState* game =newGame();
    int initialized = initializeGame(2,cards,42,game);
    if(initialized!=-1){
        testSalvager(game);
    }
    return 0;
    
}